//
//  UserCell.m
//  danpin
//
//  Created by chuangjia on 20/6/15.
//  Copyright (c) 2015 chuangjia. All rights reserved.
//

#import "UserCell.h"

@interface UserCell ()
{
    
}
@property(nonatomic,strong)UIImageView *imagesView;
@property(nonatomic,strong)UIImageView *logoView;
@property(nonatomic,strong)RTLabel *titleLabel;
@property(nonatomic,strong)RTLabel *timeLabel;
@property(nonatomic,strong)RTLabel *contentLabel;
@property(nonatomic,strong)UIImageView *lineView;
@end
@implementation UserCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor=[UIColor clearColor];
        _imagesView =[[UIImageView alloc] initWithFrame:CGRectZero];
        _imagesView.layer.cornerRadius=PHOTO_FRAME_WIDTH*1.5;
        _imagesView.layer.masksToBounds = YES;
        _imagesView.userInteractionEnabled =YES;
        [self.contentView addSubview:_imagesView];
        _titleLabel =[[RTLabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH-(PHOTO_FRAME_WIDTH+PHOTO_TIME_PADDING)*2,0)];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.textColor =[UIColor darkGrayColor];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.font = FONT(14);
        [self.contentView addSubview:_titleLabel];
        _timeLabel =[[RTLabel alloc] initWithFrame:CGRectMake(0,0, 250,20)];
        _timeLabel.backgroundColor = [UIColor clearColor];
        _timeLabel.textColor = [UIColor lightGrayColor];
        _timeLabel.textAlignment = NSTextAlignmentLeft;
        _timeLabel.font = FONT(10);
        [self.contentView addSubview:_timeLabel];
      
        _logoView =[[UIImageView alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:_logoView];
        _lineView =[[UIImageView alloc] initWithFrame:CGRectZero];
        _lineView.image =[UIImage imageNamed:@"line_xu.png"];
        [self.contentView addSubview:_lineView];
    }
    return self;
}
-(void)dealloc
{
    self.data=nil;
    self.imagesView.image =nil;
    self.imagesView=nil;
    self.titleLabel=nil;
    self.timeLabel=nil;
    self.contentLabel=nil;
    self.logoView.image =nil;
    self.logoView=nil;
    self.lineView=nil;
//     DLog(@"%s", __PRETTY_FUNCTION__);
}
- (void)drawRect:(CGRect)rect {
    
//    [super drawRect:rect];
//    self.lineView.frame=CGRectMake(0, self.bounds.size.height-1, DEVICE_WIDTH, 1);
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model other:(id)other key:(id)key indexPath:(NSIndexPath *)indexPath
{
    self.data = model;
    self.key =key;
    self.other =other;
    [self showInfo:model key:key indexPath:indexPath];
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model key:(id)key indexPath:(NSIndexPath *)indexPath
{
    self.key =key;
    self.indexPath =indexPath;
    NSDictionary *dict =(NSDictionary*)model;
    self.data =model;
    NSDictionary *user =[dict objectForKey:@"user"];
    _imagesView.frame =CGRectMake(PHOTO_FRAME_WIDTH,PHOTO_FRAME_WIDTH, PHOTO_FRAME_WIDTH*3, PHOTO_FRAME_WIDTH*3);
    NSString * strURL =[[NSString stringWithFormat:@"%@", [user objectForKey:@"largeFace"]] replaceNullString];
    if (strURL.length) {
        [_imagesView sd_setImageWithURL:[NSURL URLWithString:strURL] placeholderImage:[UIImage imageNamed:@"user_face.png"]];
        
    }
    NSString *test =[[NSString stringWithFormat:@"%@", [user objectForKey:@"nick_name"]] replaceNullString];
    [_titleLabel setText:test];
    _titleLabel.frame =CGRectMake(PHOTO_FRAME_WIDTH*5, PHOTO_FRAME_WIDTH+2,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*6, PHOTO_FRAME_WIDTH*2);
    _titleLabel.text =test;
    //
    NSString *test1 =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"upload_dateinfo"]] replaceNullString];
    [_timeLabel setText:test1];
    _timeLabel.frame=CGRectMake(PHOTO_FRAME_WIDTH*5,PHOTO_FRAME_WIDTH*2.8,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*6, PHOTO_FRAME_WIDTH*2);
    _timeLabel.text =test1;
    //
    NSString *icon =[[NSString stringWithFormat:@"%@",[dict objectForKey:@"shaidan_icon"]] replaceNullString];
    if (icon&&icon.length>0) {
        _logoView.frame =CGRectMake(DEVICE_WIDTH-32-PHOTO_FRAME_WIDTH, _imagesView.frame.origin.y, 32, 16);
        [_logoView sd_setImageWithURL:[NSURL URLWithString:icon]];
    }
    [self layoutSubviews];
}
-(void)setCallBack:(void(^)(BEventType,UIView*,id,id,NSIndexPath *))callback
{
    self.actionBlock=callback;
}
-(void)likeAction:(id)sender
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_ding,sender,self.data,nil,self.indexPath);
    }
}
-(void)commentAction:(id)sender
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_cai,sender,self.data,nil,self.indexPath);
    }
}

-(void)handleSingleTapFrom
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_comment,nil,self.data,nil,self.indexPath);
    }
}
/// 返回Cell高度
+ (CGFloat)returnCellHeight:(id)model
{
    return PHOTO_FRAME_WIDTH*5;
}
@end
